#ifndef PAGETABLE_H
#define PAGETABLE_H

#include "common.h"
#include <cassert>

#define DRAM_COPYENGINE_AREA                  0x00100000
#define SIZE_COPYENGINE_AREA                  0x00040000
#define PPCADDR_PAGETABLE_AREA 0xf0000000
#define PPCADDR_DRAM_NC      0x88000000  // Non Cached
#define PPCADDR_DRAM_C       0x98000000  // Cached

#define MM_PAGEMASK  0xC0000000
#define MM_PS1       0x00000000
#define MM_PS8       0x40000000
#define MM_PS32      0x80000000
#define MM_MMUMASK   0x3FFFFFFF
#define MM_INDEXPS1  0x00000000 // number of bits to shift MMU address for PS1
#define MM_INDEXPS8  0x00000003 // number of bits to shift MMU address for PS8
#define MM_INDEXPS32 0x00000005 // number of bits to shift MMU address for PS32

Iu32 Adr_rTableToPpc(Iu32 rTable)
{
    if ((rTable &  MM_PAGEMASK) == MM_PS8)
    {
        // Normal 8 sector per page page table
        return (((Iu32)PPCADDR_PAGETABLE_AREA) + (((rTable & MM_MMUMASK)>>MM_INDEXPS8) * 4));
    }
    else
    {
        // Special 1 sector per page table
        return (((Iu32)PPCADDR_PAGETABLE_AREA) + (((rTable & MM_MMUMASK)>>MM_INDEXPS1) * 4));
    }
}

Iu32 Adr_DramToPpc(Iu32 DramAddr)
{
    // Only DRAM addresses in the lower 128M can have permanent addresses
    assert (DramAddr < 0x08000000);
    return DramAddr + PPCADDR_DRAM_NC;
}

#endif
